﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Linq;

namespace CommunitySystem.Infrastructure.CommonMethod
{
    public class TabControlMethod
    {
        /// <summary>
        /// 在调用此方法之前 请为App.currentTabControl赋值
        /// App.currentTabControl = tabControl1;
        /// CommunitySystem.Infrastructure.CommonMethod.TabControlMethod.addNewTabItem(uc, header, tabid, Control, App.Current.Resources["tabItemStyle"] as Style);
        /// </summary>
        /// <param name="uc"></param>
        /// <param name="header"></param>
        /// <param name="tabid"></param>
        /// <param name="Control"></param>
        /// <param name="style"></param>
        public static void addNewTabItem(UserControl uc, string header, string tabid, TabControl Control, Style style)
        {
            var item = Control.Items.Where(c => ((TabItem)c).Name.Equals(tabid)).FirstOrDefault();
            if (item != null)
            {
                Control.SelectedItem = item;
                return;
            }


            TabItem tabItem = new TabItem() { Name = tabid };
            tabItem.Style = style;
            
            //ScrollViewer sv = new ScrollViewer()
            //{
            //    HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
            //    Margin = new Thickness(-4, -4,0,0),
            //    VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
            //    BorderThickness = new Thickness(0),
            //    HorizontalAlignment = HorizontalAlignment.Stretch,
            //    VerticalAlignment = VerticalAlignment.Stretch,
            //};
            //sv.Content = uc;
            //tabItem.Content = sv;

            tabItem.Content = uc;

            tabItem.Header = header;//title;  
            Control.Items.Add(tabItem);
            Control.SelectedItem = tabItem;
        }
    }
}
